<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>商品编辑</title>

	<%-- 静态包含 base标签、css样式、jQuery文件 --%>
	<%@ include file="/pages/common/head.jsp"%>

	<style type="text/css">
	h1 {
		text-align: center;
		margin-top: 200px;
	}
	
	h1 a {
		color:red;
	}
	
	input {
		text-align: center;
	}
</style>
</head>
<body>

		<div id="header">
			<img class="logo_img" alt="" src="static/img/logo.jpg" >
			<span class="wel_word">商品编辑</span>

			<%-- 静态包含 admin 管理模块的菜单  --%>
			<%@include file="/pages/common/admin_menu.jsp"%>
			
			<script type="text/javascript">
				$(function() {
					$(".updateFloat").change(function() {
						var number = this.value;
						var pattern = /^\d+(\.\d{2})?$/;
						if (pattern.test(number) == false) {
							alert("请输入非负两位小数浮点数！");
							location.reload();
						}
					});
					
					$(".updateInt").change(function() {
						var number = this.value;
						var pattern = /^\d+$/;
						if (pattern.test(number) == false) {
							alert("请输入非负整数！");
							location.reload();
						}
					});
					
					// 提交 点击事件
					$("#submit").click(function() {
						if ($("input[name='name']").val().match(/^[ ]*$/)) {
							alert("商品名不能为空！");
							return false;
						} else if ($("input[name='price']").val().match(/^[ ]*$/)) {
							alert("价格不能为空！");
							return false;
						} else if ($("input[name='productor']").val().match(/^[ ]*$/)) {
							alert("商家不能为空！");
							return false;
						}
					});
				});
			</script>

		</div>
		
		<div id="main">
			<form action="admin/productServlet" method="post">
				<input type="hidden" name="pageNo" value="${param.pageNo}">
				<input type="hidden" name="action" value="${ empty param.id ? "add" : "update" }" />
				<input type="hidden" name="id" value="${ requestScope.product.id }" />
				<table>
					<tr>
						<td>商品名</td>
						<td>价格</td>
						<td>库存</td>
						<td>销量</td>
						<td>商家</td>
						<td colspan="2">操作</td>
					</tr>		
					<tr>
						<td><input name="name" type="text" value="${requestScope.product.name}"/></td>
						<td><input class="updateFloat" name="price" type="text" value="${requestScope.product.price}"/></td>
						<td><input class="updateInt" name="counts" type="text" value="${requestScope.product.counts}"/></td>
						<td><input class="updateInt" name="sales" type="text" value="${requestScope.product.sales}"/></td>
						<td><input name="productor" type="text" value="${requestScope.product.productor}"/></td>
						<td><input id="submit" type="submit" value="提交"/></td>
					</tr>	
				</table>
			</form>
		</div>

		<%--静态包含页脚内容--%>
		<%@include file="/pages/common/footer.jsp"%>

</body>
</html>